<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组件的遍历  列表</title>
    <style>
        ul{
            border-bottom: solid 1px #ddd;
            padding-bottom: 20px;
        }
    </style>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
    <script src="../js/prop-types.js"></script>

    <script type="text/babel">
        //1. 准备数据
        let students = [
            {name: '张三', age:20, gender: '男'},
            {name: '孙红', age:20, gender: '女'},
            {name: '李四', age:21, gender: '男'},
            {name: '赵小花', age:21, gender: '女'},
        ];

        class Student extends React.Component {
            // 2. 内部声明静态属性 propType 
            static propTypes = { //属性名首字母是小写的
                name: PropTypes.string.isRequired, // 类型设置是首字母是大写的 
                age: PropTypes.number, 
                gender: PropTypes.string, //
            }

            //设置属性的默认值  default 默认  props 属性
            static defaultProps = {
                name: '张三'
            }
            
            render(){
                let {name, gender, age} = this.props;
                return <ul>
                        <li>姓名: {name}</li>
                        <li>性别: {gender}</li>
                        <li>年龄: {age}</li>
                    </ul>
            }
        }


        ReactDOM.render(<div>
            <h2>学员信息列表</h2>
                {
                    students.map((item, index) => {
                        return <Student  key={index}  {...item} />;
                    })
                }
            </div>, document.querySelector("#root"))



    </script>
</body>
</html>